#!/usr/bin/python
# Filename: back_up.py

import os
import time

#directories
source = ['/home/jadsin/a', '/home/jadsin/b']

target_dir = '/home/jadsin/backup/'

today = target_dir + time.strftime('%Y%m%d')
now = time.strftime('%H%M%S')

#add the coment
comment = raw_input('Enter a comment--> ')
if len(comment) == 0:
	target = today + os.sep + now + '.tar.gz'
else:
	target = today + os.sep + now + '_' + \
			 comment.replace(' ', '_') + '.tar.gz'

if not os.path.exists(today):
	mk_dir = "mkdir -p " + today
	if os.system(mk_dir) == 0:
		print 'Successfully created directory', today

tar_command = "tar czvf %s %s" % (target, ' '.join(source))

#run the backup
if os.system(tar_command) == 0:
	print 'Successful backup to', target
else:
	print 'Backup failure!'
